﻿Imports ccapps.persistent.DetayliFatura
Public Class CustomerContractDetayliFatura
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("user") = "" Or Session("user") Is Nothing Then
            Session("message") = "!!Session Timeout!!,Tekrar Giriş Yapmalısınız"
            Response.Clear()
            Response.Status = "302 Object Moved"
            Response.RedirectLocation = "CX_Exception.aspx"
            Response.End()
        End If
    End Sub

    Protected Sub btnCheckMSISDN_Click(sender As Object, e As EventArgs) Handles btnCheckMsisdn.Click
        Try
            Clear()
            txtCustcode.Text = ""
            ErrorMes.Text = ""
            confirmtable.Visible = False
            If txtMsisdn.Text.Length = 0 Then
                Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('MSISDN Alanının Girilmesi Zorunludur.');</script>")
            Else
                If Not txtMsisdn.Text.Length = 10 Then
                    Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('MSISDN Alanı 10 Karakter İçermelidir.');</script>")
                Else

                    Dim dt As DataTable = getcustomerInfoFromMSISDN(txtMsisdn.Text)
                    If dt.Rows.Count > 0 Then
                        lblMusteri.Text = dt.Rows(0)("NAME").ToString() + "   " + dt.Rows(0)("LASTNAME").ToString() + "   " + dt.Rows(0)("CITY").ToString()
                        lblCustcode.Text = txtMsisdn.Text
                        lblCsid.Text = dt.Rows(0)(0).ToString()
                        Loadcalldetail(lblCsid.Text)
                        confirmtable.Visible = True
                    Else
                        ErrorMes.Text = "Girmiş Olduğunuz MSISDN'e Ait Veri Bulunamamıştır"

                    End If
                End If
            End If
        Catch ex As Exception
            ErrorMes.Text = "Girmiş Olduğunuz MSISDN'e Ait Veri Bulunamamıştır"

        End Try
       





    End Sub
    Private Sub Loadcalldetail(ByVal customerid As String)

        Dim dt As DataTable = ChangeCustomerDetailedBill(Convert.ToInt32(customerid))
        If dt.Rows.Count > 0 Then
            If Convert.ToInt32(dt.Rows(0)(0)) = 1 Then
                CheckBox1.Checked = True
            Else
                CheckBox1.Checked = False

            End If

        End If
        Dim dt2 As DataTable = ListContractDetail(Convert.ToInt32(customerid))
        If dt2.Rows.Count > 0 Then
            GridView2.DataSource = dt2
            GridView2.DataBind()

        End If




    End Sub

    Protected Sub btnCheckCustcode_Click(sender As Object, e As EventArgs) Handles btnCheckCustcode.Click

        Try
            Clear()
            ErrorMes.Text = ""
            txtMsisdn.Text = ""
            confirmtable.Visible = False
            If txtCustcode.Text = "" Then
                Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('CustCode Alanın Girilmesi Zorunludur.');</script>")
            Else
                Dim dt As DataTable = getcustomerInfoFromCustcode(txtCustcode.Text)
                If dt.Rows.Count > 0 Then
                    lblMusteri.Text = dt.Rows(0)("NAME").ToString() + "   " + dt.Rows(0)("LASTNAME").ToString() + "   " + dt.Rows(0)("CITY").ToString()
                    lblCustcode.Text = txtCustcode.Text
                    lblCsid.Text = dt.Rows(0)(0).ToString()
                    Loadcalldetail(lblCsid.Text)
                    confirmtable.Visible = True
                Else
                    ErrorMes.Text = "Girmiş Olduğunuz CUSTCODE'a Ait Veri Bulunamamıştır"

                End If


            End If
        Catch ex As Exception
            ErrorMes.Text = "Girmiş Olduğunuz CUSTCODE'a Ait Veri Bulunamamıştır"
        End Try
        
    End Sub

    Protected Sub btnCheckMsisdn0_Click(sender As Object, e As EventArgs) Handles btnCheckMsisdn0.Click
      

        For Each di As GridViewRow In GridView2.Rows
            Dim chkBx As CheckBox = di.FindControl("ShowDetayliFatura")
            If chkBx.Checked = True Then
                Dim dt4 As DataTable = ChangeContractDetail(Convert.ToInt32(lblCsid.Text), 1)
            Else
                Dim dt4 As DataTable = ChangeContractDetail(Convert.ToInt32(lblCsid.Text), 0)
            End If


        Next
        Dim dt As DataTable
        If CheckBox1.Checked = True Then
            dt = ChangeCustomerDetail(Convert.ToInt32(lblCsid.Text), 1)
        Else
            dt = ChangeCustomerDetail(Convert.ToInt32(lblCsid.Text), 0)
        End If
        Try
            If Convert.ToInt32(dt.Rows(0)(0).ToString()) Then
                Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('İşlem Başarıyla Gerçekleşti.');</script>")
            Else
                Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('İşlem Gerçekleşmedi.');</script>")
            End If
        Catch ex As Exception
            Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('İşlem Gerçekleşmedi.');</script>")
        End Try







    End Sub
    Public Sub Clear()
        lblCsid.Text = ""
        lblCustcode.Text = ""
        lblMusteri.Text = ""
        CheckBox1.Checked = False
        GridView2.DataSource = Nothing
        GridView2.DataBind()
        ErrorMes.Text = ""
        confirmtable.Visible = False

    End Sub

    Protected Sub GridView2_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView2.RowDataBound

        Dim deneme As Label = e.Row.FindControl("Label1")
        Dim deneme2 As CheckBox = e.Row.FindControl("ShowDetayliFatura")



        Dim rowView As DataRowView = CType(e.Row.DataItem, DataRowView)



        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim id As Integer = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "COID").ToString())
            Dim dt As DataTable = New DataTable()
            Dim dt2 As DataTable = New DataTable()

            dt = GetMsisdnfromcoid(id)
            dt2 = GetContractDetail(id)

            Try
                deneme.Text = dt.Rows(0)(0).ToString()
                If Convert.ToInt32(dt2.Rows(0)(0)) = 1 Then
                    deneme2.Checked = True
                Else
                    deneme2.Checked = False
                End If

                ' Dim dt2 As DataTable = ServiceHist2(Convert.ToInt32(LblCoid.Text), id, RadioButtonList1.SelectedItem.Value, Convert.ToInt32(Lbltmcode.Text))
                ' deneme3.Text = Math.Round(Convert.ToDouble(dt2.Rows(0)("ONETIME").ToString()), 2).ToString() + " " + dt2.Rows(0)("ONETIMEMONEY").ToString()
                ' deneme4.Text = Math.Round(Convert.ToDouble(dt2.Rows(0)("Recurring").ToString()), 2).ToString() + " " + dt2.Rows(0)("RecurringMONEY").ToString()
                'If dt2.Rows(0)("INITIAL").ToString() = "" Then
                ' deneme5.Text = "--"
                ' Else
                ' deneme5.Text = Math.Round(Convert.ToDouble(dt2.Rows(0)("INITIAL").ToString()), 2).ToString() + " " + dt2.Rows(0)("INITIALMONEY").ToString()
                ' End If



                'deneme.Text = LblCoid.Text + " " + id + " " + Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "PROFILEID").ToString()).ToString()

            Catch ex As Exception
                ' deneme3.Text = "--"
                'deneme4.Text = "--"
                'deneme5.Text = "--"
                'deneme.Text = "--"


            End Try
           

            'deneme.Text = Convert.ToInt32(LblCoid.Text).ToString() + "  " + id.ToString() + " " + Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "PROFILEID").ToString()).ToString()

            





        End If
    End Sub
End Class